/*
	Copyright (C) 2009 Salil Bhagurkar
	
	This file is part of ViSE
	
	ViSE is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	ViSE is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public License
	along with ViSE.  If not, see <http://www.gnu.org/licenses/>.
*/

/*Currently this code is a substitute for displaying on the screen until a real screen driver is ported*/

#include <shared.h>

/*Timestamp counter*/

static inline void read_time_stamp( u32 *low, u32 *high ) {
    asm volatile( "rdtsc" : "=a" ( *low ), "=d" ( *high ) );
}

static u32 d=0;
void tsc()
{
	u32 l,h;
	read_time_stamp(&l,&h);
	printk("The timestamp = ( %x %x ) Delta = %x\n",l,h,l-d);
	d = l;
}


void memchar(u8 c)
{
	if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
		printk("%c", c);
	} else {
		printk(".");
	}
}

int debug_memory(void *start, u32 len)
{
	char *c;
	u32 i, j;
	c = start;
	for(i = 0; i < len; i+=64) {
		printk("0x%x : ", c+i);
		for(j=0; j<64; j++) {
			memchar((u8)*(c+i+j));
		}
		printk("\n");
	}
	return 0;
}


int init_debug()
{
	init_b8000(NULL);
	printk("Booting\n");
	return 0;
}
